package com.vic.backupx.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 备份交换机
 */
@Configuration
public class BackupExchangeConfig {

    // 备份交换机
    public static final String BACKUP_EXCHANGE = "backup_exchange";
    // 队列
    public static final String LOG_QUEUE = "log_queue";
    public static final String WARNING_QUEUE = "warning_queue";

    // 声明交换机
    @Bean("backup_exchange")
    public FanoutExchange backupExchange() {
        return ExchangeBuilder.fanoutExchange(BACKUP_EXCHANGE).durable(true).build();
    }

    // 声明队列
    @Bean("log_queue")
    public Queue logQueue() {
        return QueueBuilder.durable(LOG_QUEUE).build();
    }

    // 声明队列
    @Bean("warning_queue")
    public Queue warningQueue() {
        return QueueBuilder.durable(WARNING_QUEUE).build();
    }

    // 绑定
    @Bean
    public Binding logQueueBindingBackupExchange(@Qualifier("log_queue") Queue queue, @Qualifier("backup_exchange") FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }

    // 绑定
    @Bean
    public Binding warningQueueBindingBackupExchange(@Qualifier("warning_queue") Queue queue, @Qualifier("backup_exchange") FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }

}